import { stringifyParams, parseWebUrl } from "@/util/util";
import { env } from "@/config/config";

let appid, base;
if (env === "dev") {
  appid = "wxde5a65d4281ac58c";
  base = "/wx/";
} else {
  appid = "wx7da6881ec4adea96";
  base = "/wx/";
}

async function h5Auth() {
  const userToken = JSON.parse(uni.getStorageSync("userToken_zh_web") || "{}");
  if (userToken.token) return;
  getCode();
}
function getCode(qr_code = "", state = "") {
  const redirect_uri = `${window.location.origin}${base}pages/authBlank/index`;
  const wxAuthPath =
    `https://open.weixin.qq.com/connect/oauth2/authorize` +
    `?appid=${appid}` +
    `&redirect_uri=${redirect_uri}` +
    `&response_type=code` +
    `&scope=snsapi_userinfo` +
    `&state=${state}` +
    `#wechat_redirect`;
  window.location.href = wxAuthPath;
}

export { h5Auth };
